JAVA 代码规范检查工具

JAVA 代码规范检查工具

阿里代码规约插件 IDEA 版本

https://plugins.jetbrains.com/plugin/10046-alibaba-java-coding-guidelines

备用地址:

https://werty.cn/download/plugin/p3c-idea-2.0.2.zip

阿里p3c规范集成gitlab

https://www.jianshu.com/p/048627b20860

单元测试覆盖率插件

https://blog.csdn.net/lvyuan1234/article/details/82836052

IDEA 自带coverage 插件

gitlab 集成P3C PMD工具

为了便于调试,我们先自己安装一个gitlab 基于docker 很是方便

1
2
3
4
5
docker pull docker.io/twang2218/gitlab-ce-zh

docker run --detach --publish 8443:443 --publish 8190:80 --name gitlab-ce-zh --restart unless-stopped -v /mnt/gitlab/etc:/etc/gitlab -v /mnt/gitlab/log:/var/log/gitlab -v /mnt/gitlab/data:/var/opt/gitlab twang2218/gitlab-ce-zh:latest

docker exec -it gitlab-ce-zh bash

Jacoco Maven 插件使用

参考文档 https://www.jianshu.com/p/16a8ce689d60

安装引入依赖即可

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.1</version>
<configuration>
<excludes>
<!-- 这里配置我们想要排除的包路径 -->
<exclude>com/rcplatform/athena/shorturl/models/*</exclude>
<!-- 通过通配符来排除指定格式的类 -->
<!-- <exclude>**/*ShortUrl.class</exclude>-->
<!-- <exclude>**/*ShortUrlVisit.class</exclude>-->
</excludes>
</configuration>

<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>target/jacoco.exec</dataFile>
</configuration>
</execution>
</executions>
</plugin>

然后执行 mvn install 或mvn package 时就会进行测试覆盖率检查 , 同时生成测试覆盖率报告,可以在target